﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class myaccount : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Customer"] != null)
        {
            Customer cs = (Customer)Session["Customer"];
            string newCust = Request.Params["signup"];

            if (newCust != null && newCust.Equals("true"))
            {
                this.lblWelcomeText.Visible = true;
            }
            fillMyAccount(cs);
        }
        else
        {
            Response.Redirect("home.aspx");
        }

    }

    /// <summary>
    /// Method to fill up the My Account details and the Rental details on the 
    /// myAccount Page
    /// </summary>
    /// <param name="cs">Customer object</param>
    protected void fillMyAccount(Customer cs)
    {
        this.lblName.Text = cs.Name;
        this.lblEmail.Text = cs.Email;
        this.lblAddress.Text = cs.Address;
        this.lblCity.Text = cs.City;
        this.lblState.Text = cs.State;
        this.lblZip.Text = cs.Zip;

        DataSet ds = cs.getRentals(cs.Email);
        if (ds != null && ds.Tables.Count > 0)
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                this.gvRentals.DataSource = ds;
                this.gvRentals.DataBind();
            }
            else
            {
                this.gvRentals.EmptyDataText = "Currently you have no movies rented";
                this.gvRentals.DataBind();
            }
        }
        else
        {
            this.gvRentals.EmptyDataText = "Issue displaying Data";
            this.gvRentals.DataBind();
        }


    }
}
